<?php
    header("Content-type:text/html;charset=utf-8");
    if ($_POST) {
        include '../../api/config.php';
        $json = $_POST["data"];
        $data = json_decode($json);
        $id = $data->head;
        $sql = '';
        $sql_1 = '';
        $toke = md5(time());
        if ($id == '1000') {
            $name = $data->z;
            $pas = md5($data->p);
            $sql = "SELECT id,name,token FROM admin_user WHERE name='{$name}' AND pas='{$pas}'";
            //查询用户
            $sql_1 = "UPDATE admin_user SET token='{$toke}' WHERE name = '{$name}'";
            //更新用户token
        }
        //登录

        $stmt_1 = $conn->prepare($sql_1);
        $stmt_1->execute();
        // 设置结果集为关联数组
        $arr = array();
        //新建一个数组
        $arr['data'] = array();
        //存放数据
        $result_1 = $stmt_1->setFetchMode(PDO::FETCH_ASSOC);
        if ($result_1) {
            $stmt = $conn->query($sql);
            $stmt->execute();
            $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
            $arr['data'] = $stmt->fetchAll();
        
            if ($arr['data']) {
                $arr['code'] = '200';
                $arr['msg'] = '获取数据成功';
                $data = json_encode($arr);
                //把数据转换为JSON数据.
                echo $data;
            } else {
                $arr['code'] = '400';
                $arr['msg'] = '账号或密码错误';
                $data = json_encode($arr);
                //把数据转换为JSON数据.
                echo $data;
            }
        } else {
            $arr['code'] = '400';
            $arr['msg'] = '登入失败';
            $data = json_encode($arr);
            //把数据转换为JSON数据.
            echo $data;
        }
        $conn = null;
    } else {
        echo "<script>\r\n    window.location.href = '../../';\r\n    </script>";
    }